package com.sfx.concurrent.demo.concurrent.TestSchedule;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2023-01-27
 * Time: 16:05
 */
@Slf4j(topic = "c.TestSchedule")
public class TestSchedule {
    public static void main(String[] args) {
        ScheduledExecutorService pool = Executors.newScheduledThreadPool(1);
        log.debug("start");
        pool.scheduleAtFixedRate(()->{
            log.debug("running...");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },1,1,TimeUnit.SECONDS);
    }
    public static void method1() {
        ScheduledExecutorService pool = Executors.newScheduledThreadPool(2);
        pool.schedule(()->{
            int x = 9/0;
            log.debug("task1");
        },1, TimeUnit.SECONDS);

        pool.schedule(()->{
            log.debug("task2");
        },1, TimeUnit.SECONDS);
        log.debug("start");
    }
}
